package com.zb.zeus.system.api.factory;

import com.zb.zeus.common.core.domain.R;
import com.zb.zeus.system.api.RemoteSmsService;
import com.zb.zeus.system.api.RemoteSysWxMsgService;
import com.zb.zeus.system.api.domain.dto.CheckSmsCodeDTO;
import com.zb.zeus.system.api.domain.dto.GetSmsCodeDTO;

import org.springframework.stereotype.Component;

import javax.validation.Valid;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author liangfan
 * @date 2021/07/14 19:52
 **/
@Component
@Slf4j
public class RemoteSmsFallbackFactory  implements FallbackFactory<RemoteSmsService> {

    @Override
    public RemoteSmsService create(Throwable throwable) {
        log.error("短信校验调用失败:", throwable);
        return new RemoteSmsService(){
            @Override
            public R getSmsCode(@Valid GetSmsCodeDTO getSmsCodeDTO) {
                return R.fail("发验证码失败:" + throwable.getMessage());
            }

            @Override
            public R checkSmsCode(@Valid CheckSmsCodeDTO checkSmsCodeDTO) {
                return R.fail("校验验证码失败:" + throwable.getMessage());
            }
        };
    }
}
